/* documents about daemon(): man daemon 
 * Compile: gcc daemon.c -o daemon_example
 * Run: ./daemon_example
 * < 1mins passed...> 
 * cat /var/log/syslog | grep daemon_example
 * --> Jun 30 15:27:37 dell ./daemon_example[9096]: this is 1 times
 * --> Jun 30 15:28:07 dell ./daemon_example[9096]: this is 2 times
 * Kill: kill 9096 <-------------------------|(pid)
 */
#define _BSD_SOURCE
#include <unistd.h>
#include <syslog.h>

int main(int argc,char *argv[])
{
	int times=1;

	/* set logging mask and open syslog */
	setlogmask(LOG_UPTO(LOG_NOTICE));
	openlog(argv[0],LOG_CONS|LOG_NDELAY|LOG_PID,LOG_LOCAL1);

	daemon(0,0);

	while(1)
	{
		syslog(LOG_NOTICE,"this is %d times",times++);
		sleep(30);
	}

	closelog();
	return 0;
}

/* More abot daemon, please see:
 * http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html
 */
